package sadi.client;

import java.awt.*;

import javax.swing.*;

public class ListItem extends JPanel 
{
	private WikiItem wiki;
	private int index;
	private String title;
	private String author;
	private JLabel jlbAuthor;
	private JCheckBox jcb;
	

	//private GridBagConstraints gbc;
	
	public ListItem(int index, String wikiTitle, String author)
	{
		this.index = index;
		this.title = wikiTitle;
		this.author = author;
		
		//Setup the components
		wiki = new WikiItem(index, wikiTitle);
			wiki.setHorizontalTextPosition(SwingConstants.LEFT);
		jlbAuthor = new JLabel(author);
		jcb = new JCheckBox();
		
		//Add inside the panel
		/*setLayout(new GridBagLayout());
		gbc = new GridBagConstraints();
		this.addCompWeight(this, wiki, gbc, GridBagConstraints.HORIZONTAL, 0, 0, 1, 1, 0.8, 1.0);
		this.addCompWeight(this, jlbAuthor, gbc, GridBagConstraints.HORIZONTAL, 1, 0, 1, 1, 0.1, 1.0);
		this.addCompWeight(this, jcb, gbc, GridBagConstraints.HORIZONTAL, 2, 0, 1, 1, 0.1, 1.0);*/
	}
	
	public int getIndex()
	{
		return index;
	}
	
	public WikiItem getWikiItem()
	{
		return wiki;
	}
	
	public JLabel getJLabelAuthor()
	{
		return jlbAuthor;
	}
	
	public JCheckBox getCheckBox()
	{
		return jcb;
	}
	public String getTitle()
	{
		return title;
	}
	
	public String getAuthor()
	{
		return author;
	}
	
	public boolean isCheck()
	{
		if (jcb.getSelectedObjects() != null)
			return true;
		else
			return false;
	}
	
	/*private void setUpGBC()
	{
		gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.anchor = GridBagConstraints.CENTER;
		gbc.insets = new Insets(2,2,2,2);
		gbc.ipadx = 0;
		gbc.ipady = 0;
		gbc.weightx = 0;
		gbc.weighty = 0;
	}
	
	private void addCompWeight(Container parentCom, Component childCom, GridBagConstraints g, int gbcFill, int x, int y, int numOfCol, int numOfRow, double weightX, double weightY)
	{
		
		int original_fill = g.fill;
		g.fill = gbcFill; 
		double original_WeightX = g.weightx;
		double original_WeightY = g.weighty;
		g.weightx = weightX;
		g.weighty = weightY;
		g.gridx = x;
		g.gridy = y;
		g.gridwidth = numOfCol;
		g.gridheight = numOfRow;
		parentCom.add(childCom, g);
	
		g.weightx = original_WeightX;
		g.weighty = original_WeightY;
		g.fill = original_fill;
	}*/
	
	public static void main (String [] args)
	{
		JFrame f = new JFrame();
		ListItem li = new ListItem (1, "String", "author");
		f.add(li);
		
		//Define the JFrame properties
		f.setTitle("Shared Wiki");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setSize(1024,600);
		f.setResizable(true);
		//this.pack();
		f.setLocationRelativeTo(null);
		f.setVisible(true);
	}

}
